package org.penguin.study.bk.eventbus;

import org.greenrobot.eventbus.EventBus;
import org.penguin.study.bk.eventbus.subscried.OrderListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class EventHelper {

    @Autowired
    private EventBus eventBus;

    @Autowired
    private OrderListener orderListener;

    @PostConstruct
    public void init() {
        eventBus.register(orderListener);
    }

    @PreDestroy
    public void destroy(){
        eventBus.unregister(orderListener);
    }

    public void postEvent(Object o) {
        eventBus.post(o);
    }
}
